{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.11.3\n",
      "blas_mkl_info:\n",
      "    libraries = ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']\n",
      "    library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
      "    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
      "    include_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
      "blas_opt_info:\n",
      "    libraries = ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']\n",
      "    library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
      "    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
      "    include_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
      "openblas_lapack_info:\n",
      "  NOT AVAILABLE\n",
      "lapack_mkl_info:\n",
      "    libraries = ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']\n",
      "    library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
      "    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
      "    include_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\include']\n",
      "lapack_opt_info:\n",
      "    libraries = ['mkl_core_dll', 'mkl_intel_lp64_dll', 'mkl_intel_thread_dll']\n",
      "    library_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\lib']\n",
      "    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]\n",
      "    include_dirs = ['C:/ProgramData/Anaconda3\\\\Library\\\\include']\n"
     ]
    }
   ],
   "source": [
    "print(np.__version__)\n",
    "np.show_config()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.  0.  0.  0.  1.  0.  0.  0.  0.  0.]\n"
     ]
    }
   ],
   "source": [
    "Z = np.zeros(10)\n",
    "Z[4] = 1\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25\n",
      " 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10]\n"
     ]
    }
   ],
   "source": [
    "Z = np.arange(10, 50)\n",
    "Z = Z[::-1]\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 2]\n",
      " [3 4 5]\n",
      " [6 7 8]]\n"
     ]
    }
   ],
   "source": [
    "Z = np.arange(0, 9).reshape(3, 3)\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 4]\n",
      "[1 2 4]\n"
     ]
    }
   ],
   "source": [
    "Z = np.array([1,2,0,0,4,0])\n",
    "print(Z[Z>0])\n",
    "print(Z[np.nonzero(Z)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.  0.  0.]\n",
      " [ 0.  1.  0.]\n",
      " [ 0.  0.  1.]]\n"
     ]
    }
   ],
   "source": [
    "Z = np.eye(3, 3)\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0.09453382  0.23411117  0.36097862]\n",
      "  [ 0.60760997  0.47182099  0.35458565]\n",
      "  [ 0.58698442  0.82647204  0.14016116]]\n",
      "\n",
      " [[ 0.29292865  0.95452322  0.68847461]\n",
      "  [ 0.64441502  0.70930403  0.97291624]\n",
      "  [ 0.61460191  0.09958079  0.73375049]]\n",
      "\n",
      " [[ 0.2363079   0.55050297  0.61469357]\n",
      "  [ 0.62379931  0.60317252  0.00911214]\n",
      "  [ 0.83618016  0.18177865  0.10742265]]]\n"
     ]
    }
   ],
   "source": [
    "Z = np.random.random((3,3,3))\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第 37 个: 0.0181627965941\n",
      "第 19 个: 0.99575635188\n"
     ]
    }
   ],
   "source": [
    "Z = np.random.random((10, 10))\n",
    "print('第', np.argmin(Z), '个:', np.min(Z))\n",
    "print('第', np.argmax(Z), '个:', np.max(Z))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.525400198602\n"
     ]
    }
   ],
   "source": [
    "Z = np.random.random(30)\n",
    "m = Z.mean()\n",
    "print(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  0.  0.  0.  0.  0.  0.  0.  0.  1.]\n",
      " [ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]]\n"
     ]
    }
   ],
   "source": [
    "Z = np.ones((10, 10))\n",
    "Z[1:-1,1:-1]=0\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0 * np.nan\n",
    "np.nan == np.nan\n",
    "np.inf > np.nan\n",
    "np.nan - np.nan\n",
    "0.3 == 3 * 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0 0 0]\n",
      " [1 0 0 0 0]\n",
      " [0 2 0 0 0]\n",
      " [0 0 3 0 0]\n",
      " [0 0 0 4 0]]\n"
     ]
    }
   ],
   "source": [
    "Z = np.diag(1+np.arange(4),k=-1)\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]\n",
      " [0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]\n",
      " [0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]\n",
      " [0 1 0 1 0 1 0 1]\n",
      " [1 0 1 0 1 0 1 0]]\n"
     ]
    }
   ],
   "source": [
    "Z = np.zeros((8,8),dtype=int)\n",
    "Z[1::2,::2] = 1\n",
    "Z[::2,1::2] = 1\n",
    "print(Z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  1.00000000e+00   0.00000000e+00   0.00000000e+00]\n",
      " [ -8.88178420e-16   1.00000000e+00   2.22044605e-16]\n",
      " [  0.00000000e+00   0.00000000e+00   1.00000000e+00]] 0\n"
     ]
    }
   ],
   "source": [
    "Z = np.array([[1, 3, 4],[2, 4, 6],[3, 1, 2]])\n",
    "N = np.linalg.inv(Z)\n",
    "print(Z.dot(N),0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
